﻿using System;

namespace Microsoft.Popfly.GameCreator.GameEngine.Events
{
    public class DelayEventChecker : IEventChecker
    {
        private Game m_game;
        private BehaviorOwner m_owner;
        private double m_delayInSeconds;
        private double m_totalElapsedTimeInSeconds;

        public DelayEventChecker(Game game, BehaviorOwner owner, double delayInSeconds)
        {
            m_game = game;
            m_owner = owner;
            m_delayInSeconds = delayInSeconds;
            m_totalElapsedTimeInSeconds = 0;
        }

        #region IEventChecker Members

        public bool FireThisFrame(double elapsedTimeInSeconds, out BehaviorOwner sender, out PGCEventArgs args)
        {
            m_totalElapsedTimeInSeconds += elapsedTimeInSeconds;

            if (m_totalElapsedTimeInSeconds >= m_delayInSeconds)
            {
                sender = m_owner.Scene;
                args = null;

                m_owner.RemoveBehavior(this);

                return true;
            }
            else
            {
                sender = null;
                args = null;

                return false;
            }
        }

        // not currently implemented in the designer, but could be
        public bool IsOfEventType(string eventType)
        {
            return eventType == "Delay";
        }

        #endregion
    }
}
